


const baseUrl2 = "https://myr.wissun.net"

const request = (url = '', date = {}, type = 'POST', header = {
	'content-type': 'application/json'
}) => {
	var token=uni.getStorageSync("fahuo_jxs_token")
	if(token){
		header.token=token
	}
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: baseUrl2 + url,
			data:date,
			header: header,
			timeout:300000
		}).then((response) => {
			if(response.length > 1){
				response=response[1];
			}
			setTimeout(function() {
				uni.hideLoading();
			}, 200);
			
			if(response.data.code == 200){
				resolve(response.data);
			}else if(response.data.code == 501){
				uni.showModal({
					title: '提示',
					showCancel: false,
					content: "会话已过期,请重新登录"
				})
				setTimeout(function(){
					uni.redirectTo({
						url:"/pages/index/loginmain"
					})
				},2000)
			}
			else{
				uni.showModal({
					title: '提示',
					showCancel: false,
					content: response.data.message
				})
			}
		}).catch(error => {
			uni.hideLoading();
			uni.showModal({
				title: '提示',
				showCancel: false,
				content: '请求结果异常'
			})
			let [err, res] = error;
			reject(err)
		})
	});
}

export default request